package reflect;

import java.lang.reflect.Constructor;

/**
 * 使用无参和有参构造器实例化Student对象
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Student");
        Constructor con1 = cls.getConstructor();
        Object obj1 = con1.newInstance();
        System.out.println(obj1);

        // 获取有参构造器
        Constructor con = cls.getConstructor(String.class,int.class,char.class);
        Object obj = con.newInstance("张三",20,'男');
        System.out.println(obj);
    }
}
